package servlet;

import bean.Result;
import biz.ItemBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "BackNameServlet", value = "/BackNameServlet.s")
public class BackNameServlet extends HttpServlet {
    private ItemBiz biz = new ItemBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        String s = biz.queryAmount();
        System.out.println(s);
        int total = Integer.parseInt("null".equals(s) ? "0" : s);
        map.put("total", total);
        String json = new Gson().toJson(map);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
